﻿using System;
using System.Collections.Generic;
using System.Linq;

using Microsoft.WowAddonStudio.Lua.Parser;

namespace Microsoft.WowAddonStudio.Lua.AST
{
    /// <summary>
    /// Represents a local declaration node in the AST for the Lua code file.
    /// </summary>
    public class LocalDeclaration : Statement
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="LocalDeclaration"/> class.
        /// </summary>
        /// <param name="location">The location of the node.</param>
        public LocalDeclaration(LexLocation location)
            : base(location)
        {
        }

		/// <summary>
		/// Gets or sets the list of identifiers being declared.
		/// </summary>
		/// <value>The identifier list.</value>
        public Identifier IdentifierList { get; set; }

        /// <summary>
        /// Gets the identifiers declared in the local scope.
        /// </summary>
        /// <returns>An enumerable collection of <see cref="Identifier"/>s.</returns>
        public IEnumerable<Identifier> GetIdentifiers()
        {
            return GetChildNodes().OfType<Identifier>();
        }

        /// <summary>
		/// Gets the child nodes of the node.
		/// </summary>
		/// <returns>An enumerable collection of <see cref="Node"/>s.</returns>
        public override IEnumerable<Node> GetChildNodes()
        {
            if (IdentifierList != null)
            {
                foreach (var identifier in IdentifierList)
                    yield return identifier;
            }
        }

        /// <summary>
        /// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </summary>
        /// <returns>
        /// A <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </returns>
        public override string ToString()
        {
            return String.Format("LocalDeclaration");
        }
	}
}
